package com.wanxs.mall.ware.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.wanxs.mall.common.page.PageData;
import com.wanxs.mall.common.service.impl.CrudServiceImpl;
import com.wanxs.mall.common.utils.Query;
import com.wanxs.mall.ware.dao.WareInfoDao;
import com.wanxs.mall.ware.dto.WareInfoDTO;
import com.wanxs.mall.ware.entity.WareInfoEntity;
import com.wanxs.mall.ware.service.WareInfoService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;

import java.util.Map;

/**
 * 仓库信息
 *
 * @author wanxs 130001934@qq.com
 * @since 1.0.0 2023-09-04
 */
@Service
public class WareInfoServiceImpl extends CrudServiceImpl<WareInfoDao, WareInfoEntity, WareInfoDTO> implements WareInfoService {

    @Override
    public QueryWrapper<WareInfoEntity> getWrapper(Map<String, Object> params){
        String id = (String)params.get("id");

        QueryWrapper<WareInfoEntity> wrapper = new QueryWrapper<>();
        wrapper.eq(StringUtils.isNotBlank(id), "id", id);

        return wrapper;
    }


    @Override
    public PageData<WareInfoEntity> queryPage(Map<String, Object> params) {
        QueryWrapper<WareInfoEntity> wrapper = new QueryWrapper<>();
        // 获取查询的关键字
        String key = (String) params.get("key");
        if(!StringUtils.isEmpty(key)){
            wrapper.eq("id",key).or()
                    .like("name",key).or()
                    .like("address",key).or()
                    .like("areacode",key);
        }
        IPage<WareInfoEntity> page = baseDao.selectPage(
                new Query<WareInfoEntity>().getPage(params),
                wrapper
        );

        return  new PageData<WareInfoEntity>(page.getRecords(),page.getTotal());
    }
}